import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { SGuildWarehouseApply } from "../../../../../Message/Game/SGuildWarehouseApply";
import { ItemData } from "../../../resource/info/ItemData";
import { JSON } from "../../../../../com/mui/serialization/json/JSON";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { EGuildWarehouseState } from "../../../../../Message/Game/EGuildWarehouseState";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { BaseItem } from "../../common/BaseItem";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GButton } from "../../../../../com/mui/controls/GButton";
//class ApplyRenderer
    
    export  class ApplyRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=null;
            super.data = arg1;
            this._applyInfo = arg1 as SGuildWarehouseApply;
            if (this._applyInfo) 
            {
                if (this._applyInfo.itemCode > 0) 
                {
                    loc1 = new ItemData(this._applyInfo.itemCode);
                    loc1.itemAmount = this._applyInfo.amount;
                    if (this._applyInfo.jsStr != "") 
                    {
                        loc1.setItemExInfo(JSON.deserialize(this._applyInfo.jsStr));
                    }
                    this._baseItem.itemData = loc1;
                    this._name = ItemsUtil.getItemName(loc1);
                }
                else 
                {
                    this._baseItem.itemData = null;
                    this._name = GameDefConfig.instance.getEPrictUnitName(this._applyInfo.unit);
                    if (this._applyInfo.unit == 0 || this._applyInfo.unit == 1) 
                    {
                        this._baseItem.source = GlobalClass.getBitmapData(ImagesConst.Market_Coin);
                    }
                    else if (this._applyInfo.unit == 2 || this._applyInfo.unit == 3) 
                    {
                        this._baseItem.source = GlobalClass.getBitmapData(ImagesConst.Market_Gold);
                    }
                }
                this._nameTxt.htmlText = this._name + "  *" + this._applyInfo.amount;
                loc2 = "";
                if (this._applyInfo.state.value() != EGuildWarehouseState._EGuildWarehouseApply) 
                {
                    if (this._applyInfo.state.value() != EGuildWarehouseState._EGuildWarehouseReply) 
                    {
                        if (this._applyInfo.state.value() == EGuildWarehouseState._EGuildWarehouseCanGet) 
                        {
                            loc2 = Language.getString(57246);
                            this._operBtn.label = Language.getString(57245);
                            this._operType = "Draw";
                        }
                    }
                    else 
                    {
                        loc2 = Language.getString(57244);
                        this._operBtn.label = Language.getString(57245);
                        this._operType = "Draw";
                    }
                }
                else 
                {
                    loc2 = Language.getString(57242);
                    this._operBtn.label = Language.getString(57243);
                    this._operType = "Cancel";
                }
                this._statusTxt.htmlText = loc2;
                this._operBtn.drawNow();
            }
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 240, 50, this);
            this._nameTxt = ObjCreate.createTextField("", 67, 8, 170, 20, this);
            ObjCreate.createBg(14, 5, 38, 38, this, ImagesConst.PackItemBg);
            this._baseItem = new BaseItem();
            this._baseItem.width = 32;
            this._baseItem.height = 32;
            this._baseItem.move(16, 7);
            this._baseItem.isDragAble = false;
            this.addChild(this._baseItem);
            this._amountTxt = ObjCreate.createTextField("", 140, 8, 170, 20, this);
            this._statusTxt = ObjCreate.createTextField("", 67, 30, 170, 20, this, GlobalStyle.textFormat5);
            this._operBtn = ObjCreate.createGButton("", 188, 7, 49, 28, this);
            this._operBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOperBtnClickHandler);
            return;
        }

        /* internal  */onOperBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (this._applyInfo) 
            {
                if (this._operType != "Draw") 
                {
                    if (this._operType == "Cancel") 
                    {
                        if (this._applyInfo.itemCode == 0) 
                        {
                            loc1 = new Map<any, any> /* flash.utils.Dictionary */();
                            loc1[this._applyInfo.unit] = this._applyInfo.amount;
                        }
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarehouseCancelApply, {"uid": this._applyInfo.uid, "moneyMap": loc1}));
                    }
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarehouseDraw, this._applyInfo.uid));
                }
            }
            return;
        }

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_amountTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_statusTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_operBtn: GButton;

        /* internal */ /* var */_applyInfo: SGuildWarehouseApply;

        /* internal */ /* var */_operType: string="";

        /* internal */ /* var */_name: string;
    }
